package pri.damai.xiaowu.common.core.exception;

import pri.damai.xiaowu.common.core.enums.base.StringEnumerator;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 全局异常
 * @Desc
 * @Author DaMai
 * @Date 2021/3/23 15:29
 * 但行好事，莫问前程。
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class GlobalException extends RuntimeException {

    /** 错误码 */
    private String code;
    /** 错误信息 */
    private String msg;

    public GlobalException(StringEnumerator resultEnum) {
        super(resultEnum.desc());
        this.code = resultEnum.code();
        this.msg = resultEnum.desc();
    }

    public GlobalException(String code, String msg) {
        super(msg);
        this.code = code;
        this.msg = msg;
    }

    public static void throwException(StringEnumerator resultEnum) {
        throw new GlobalException(resultEnum);
    }

    public static void throwException(String code, String msg) {
        throw new GlobalException(code, msg);
    }
}
